<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="../css/loginto.css" />
	</head>
	<body>
		<div id="mainbody">
			<table>
				<tr>
					<td><span>用户名：</span></td>
					<td><input type="text" name="username" id="username" value="刘宇宏"/></td>
					<td><span id="uname" ></span></td>
				</tr>
				<tr>
					<td><span>密码：</span></td>
					<td><input type="password" name="password" id="password" value="123456"/></td>
					<td><span id="pwd"></span></td>
				</tr>
				<tr>
					<td><span>验证码:</span></td>
					<td ><input type="text" name="checkName"id="checkName"/><span id="checkNameValue"></span></td>
					<td><img src="http://localhost:8080/java-servlet2/user.do?method=sendIdentFyingCode" alt="验证码" id="img"/></td>
				</tr>
				<tr>
					<td><span>手机验证:</span></td>
					<td><input type="text" name="phoneCheck" id="phoneCheck"/></td>
					<td><input type="button" id="btn01" value="发送验证"/></td>	
				</tr>
				<tr>
					<td><input type="checkbox" id="box"/></td>
					<td><span>十天免登入</span></td>
					<td></td>
				</tr>
				<tr>
					<td colspan="3"><input type="button" value="登入" id="btn"/></td>
				</tr>
			</table>
		</div>
	</body>
	<script type="text/javascript" src="../js/jquery-1.4.4.js" ></script>
<script>
		$(function(){
			/**
			 * 判断用户名是否存在！
			 */
			$('input[name="username"]').blur(function(){
				var username=$('input[name="username"]').val();
				var method='';
				var data={
					username:username,
					method:'findByUserName'
				}
				if(''==username){
					   $('#uname').html('账号不能为空！');
				}else{	
					$.post('http://localhost:8080/java-servlet2/user.do',data,function(jsonData){
						if(jsonData==null){
							 $('#uname').html('用户名不存在！');
						}
					},'json');
				}
			});	
			$('input[name="username"]').click(function(){
				$('#uname').html('');
			});
			
			
			/**
			 * 判断密码是否正确！
			 */
			$('input[name="password"]').blur(function(){
				var password=$('input[name="password"]').val();
				var method='';
				if(''==password){
					   $('#pwd').html('密码不能为空！');
				}else{	
					var data={
						username:$('input[name="username"]').val(),
						password:$('input[name="password"]').val(),
						method:'checkUserLogin'
					}
					$.post('http://localhost:8080/java-servlet2/user.do',data,function(jsonData){

						if(jsonData.pwdresult!='1'||jsonData.pwdresult==null){
							 $('#pwd').html('密码错误！');
						}
					},'json');
				}

			});
			$('input[name="password"]').click(function(){
				$('#pwd').html('');
			});
			
			//获取验证码 identifying code
			$('input[name="checkName"]').blur(function(){
				var checkName=$('input[name="checkName"]').val();
				var method='';
				if(''==checkName){
					   $('#checkNameValue').html('不能空！');
				}else{	
					var data={
						checkName:checkName,
						method:'checkIdentyflyImg'
					}
					$.post('http://localhost:8080/java-servlet2/user.do',data,function(jsonData){
						if(jsonData=='error')  $('#checkNameValue').html('验证码错误！');
					},'json');
				}

			});
			$('input[name="checkName"]').click(function(){
				$('#checkNameValue').html('');
			});
			
			
			$('#btn01').click(function(){
				var data={
					 AppKey: 'go9dnk49bkd9jd9vmel1kglw0803mgq3',
					 CurTime: new Date(),
					 CheckSum: '9e9db3b6c9abb2e1962cf3e6f7316fcc55583f86',
					 Nonce: '4tgggergigwow323t23t',
					 ContentType: 'application/x-www-form-urlencoded',
					 mobile:'15989309781'
				}
				$.post('https://api.netease.im/sms/sendcode.action',data,function(jsonData){
					console.log(jsonData)
				},'json');
			});
			
		});
	</script>
</html>
